home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume1 / rogue / patch3 < prev   
Encoding:
Internet Message Format  |  1992-01-13  |  37.1 KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.tek.com (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v12i097:  rogue - a rogue 5.3 clone, Patch3
  5. Message-ID: <1764@masterCNA.TEK.COM>
  6. Date: 13 Sep 91 18:38:07 GMT
  7. Sender: news@masterCNA.TEK.COM
  8. Lines: 1500
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: seaotter@ATHENA.MIT.EDU
  12. Posting-number: Volume 12, Issue 97
  13. Archive-name: rogue/Patch3
  14. Patch-To: rogue: Volume 1, Issue 11-16
  15.  
  16.  
  17. [[Here are the changes necessary to adapt Tim Stoehr's rogue clone to VMS.
  18. It consists of a new machdep.c, a Makefile for VMS and a .com file that
  19. emulates it, a package of terminal functions wrapped into vmsterm.c and
  20. vmsterm.h, and a small patchfile.  I have refrained from adding new com-
  21. mands or fiddling with the code unnecessarily: I might do that later.
  22.  
  23. --Mike Zraly]]
  24.  
  25.  
  26. #! /bin/sh
  27. # This is a shell archive.  Remove anything before this line, then unpack
  28. # it by saving it into a file and typing "sh file".  To overwrite existing
  29. # files, type "sh file -c".  You can also feed this as standard input via
  30. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  31. # will see the following message at the end:
  32. #        "End of shell archive."
  33. # Contents:  BUGS3 Make.com Makefile.vms Patches03 README.VMS machdep.c
  34. #   vmsterm.c vmsterm.h
  35. # Wrapped by seaotter@e40-008-10 on Fri Aug 23 23:47:03 1991
  36. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  37. if test -f 'BUGS3' -a "${1}" != "-c" ; then 
  38.   echo shar: Will not clobber existing file \"'BUGS3'\"
  39. else
  40. echo shar: Extracting \"'BUGS3'\" \(972 characters\)
  41. sed "s/^X//" >'BUGS3' <<'END_OF_FILE'
  42. XHere is yet another list for fixes for Tim Stoehr's rogue clone.
  43. XI was not able to contact Tim at his Tektronix email address, so
  44. XI added these myself.  This introduces a diversion from the rogue
  45. Xclone distributed by Berkeley but I don't really see them as being
  46. Xinterested in VMS compatability.
  47. X            Mike Zraly
  48. X            mzraly@ldbvax.dnet.lotus.com
  49. X            or c/o seaotter@athena.mit.edu
  50. X    ----------------------------------------------------
  51. X
  52. X 1.)    Add VMS compatability through changes to machdep.c (add
  53. X    appropriate code), the introduction of one small #define
  54. X    to rogue.h, and a package of VMS keyboard i/o functions
  55. X    I developed (vmsterm.c and vmsterm.h).  I also added a
  56. X    Makefile for VMS suitable for use with the VMS Make program
  57. X    (available via anonymous FTP from vmsd.oac.uci.edu or
  58. X    pomona.claremont.edu)
  59. X
  60. X 2.)    Replace comment within comment in machdep.c (circa line 41)
  61. X    with [* ... *] instead of /* ... */
  62. X
  63. X 3.)    Change patchlevel.h
  64. X
  65. X 4.)    Change version message in play.c
  66. X
  67. X
  68. END_OF_FILE
  69. if test 972 -ne `wc -c <'BUGS3'`; then
  70.     echo shar: \"'BUGS3'\" unpacked with wrong size!
  71. fi
  72. # end of 'BUGS3'
  73. fi
  74. if test -f 'Make.com' -a "${1}" != "-c" ; then 
  75.   echo shar: Will not clobber existing file \"'Make.com'\"
  76. else
  77. echo shar: Extracting \"'Make.com'\" \(846 characters\)
  78. sed "s/^X//" >'Make.com' <<'END_OF_FILE'
  79. X$ On Control_Y Then Goto The_Exit
  80. X$ On Error Then Goto The_Exit
  81. X$ cc  curses
  82. X$ cc  hit
  83. X$ cc  init
  84. X$ cc  inventory
  85. X$ cc  level
  86. X$ cc  machdep
  87. X$ cc  main
  88. X$ cc  message
  89. X$ cc  monster
  90. X$ cc  move
  91. X$ cc  object
  92. X$ cc  pack
  93. X$ cc  play
  94. X$ cc  random
  95. X$ cc  ring
  96. X$ cc  room
  97. X$ cc  save
  98. X$ cc  score
  99. X$ cc  spec_hit
  100. X$ cc  throw
  101. X$ cc  trap
  102. X$ cc  use
  103. X$ cc  zap
  104. X$ cc  vmsterm
  105. X$ open/write foo rtl.opt
  106. X$ write foo "SYS$LIBRARY:VAXCRTLG/SHARE"
  107. X$ close foo
  108. X$ link /exe=rogue curses.obj,    hit.obj,    init.obj,-
  109. X    inventory.obj,        level.obj,    machdep.obj,-
  110. X    main.obj,        message.obj,    monster.obj,-
  111. X    move.obj,        object.obj,    pack.obj,-
  112. X    play.obj,        random.obj,    ring.obj,-
  113. X    room.obj,        save.obj,    score.obj,-
  114. X    spec_hit.obj,        throw.obj,    trap.obj,-
  115. X    use.obj,        zap.obj,    vmsterm.obj, rtl.opt/opt
  116. X$ rogue :== $'f$env("default")'rogue.exe
  117. X$The_Exit:
  118. X$ Save_Status = $STATUS
  119. X$ exit Save_Status
  120. END_OF_FILE
  121. if test 846 -ne `wc -c <'Make.com'`; then
  122.     echo shar: \"'Make.com'\" unpacked with wrong size!
  123. fi
  124. # end of 'Make.com'
  125. fi
  126. if test -f 'Makefile.vms' -a "${1}" != "-c" ; then 
  127.   echo shar: Will not clobber existing file \"'Makefile.vms'\"
  128. else
  129. echo shar: Extracting \"'Makefile.vms'\" \(934 characters\)
  130. sed "s/^X//" >'Makefile.vms' <<'END_OF_FILE'
  131. X#
  132. X#    VMS makefile for rogue
  133. X#
  134. X
  135. XROGUE_OBJS = curses.obj,    hit.obj,    init.obj,    \
  136. X    inventory.obj,        level.obj,    machdep.obj,    \
  137. X    main.obj,        message.obj,    monster.obj,    \
  138. X    move.obj,        object.obj,    pack.obj,    \
  139. X    play.obj,        random.obj,    ring.obj,    \
  140. X    room.obj,        save.obj,    score.obj,    \
  141. X    spec_hit.obj,        throw.obj,    trap.obj,    \
  142. X    use.obj,        zap.obj,    vmsterm.obj
  143. X
  144. XCC = cc
  145. X
  146. XCFLAGS = 
  147. X
  148. Xrogue: $(ROGUE_OBJS) rtl.opt
  149. X    link /exe=rogue $(ROGUE_OBJS), rtl.opt/opt
  150. X    rogue :== $'f$env("default")'rogue.exe
  151. X
  152. Xrtl.opt:
  153. X    open/write foo rtl.opt
  154. X    write foo "SYS$LIBRARY:VAXCRTLG/SHARE"
  155. X    close foo
  156. X
  157. X*.obj:    *.c rogue.h
  158. X    $(CC) $(CFLAGS) $*
  159. X
  160. Xallclean:    clean
  161. X    msg = f$env("MESSAGE")
  162. X    set mess /nofac/noid/nosev/notext
  163. X    delete/nolog    rogue.exe;*
  164. X    set mess 'msg'
  165. X
  166. Xclean:
  167. X    msg = f$env("MESSAGE")
  168. X    set mess /nofac/noid/nosev/notext
  169. X    purge/nolog
  170. X    delete/nolog    *.lis;*
  171. X    delete/nolog    *.obj;*
  172. X    delete/nolog    rogue.scores;*
  173. X    delete/nolog    rogue.save;*
  174. X    delete/nolog    rtl.opt;*
  175. X    set mess 'msg'
  176. END_OF_FILE
  177. if test 934 -ne `wc -c <'Makefile.vms'`; then
  178.     echo shar: \"'Makefile.vms'\" unpacked with wrong size!
  179. fi
  180. # end of 'Makefile.vms'
  181. fi
  182. if test -f 'Patches03' -a "${1}" != "-c" ; then 
  183.   echo shar: Will not clobber existing file \"'Patches03'\"
  184. else
  185. echo shar: Extracting \"'Patches03'\" \(1307 characters\)
  186. sed "s/^X//" >'Patches03' <<'END_OF_FILE'
  187. X*** patchlevel.h.orig    Wed Aug 14 06:29:16 1991
  188. X--- patchlevel.h    Wed Aug 21 11:57:22 1991
  189. X***************
  190. X*** 1 ****
  191. X! #define PATCHLEVEL 2
  192. X--- 1 ----
  193. X! #define PATCHLEVEL 3
  194. X*** play.c.orig    Wed Aug 14 06:26:18 1991
  195. X--- play.c    Wed Aug 21 11:58:38 1991
  196. X***************
  197. X*** 1,4 ****
  198. X--- 1,8 ----
  199. X  /*
  200. X+  *    This code was adapted for VMS by Mike Zraly
  201. X+  */
  202. X+ 
  203. X+ /*
  204. X   * play.c
  205. X   *
  206. X   * This source herein may be modified and/or distributed by anybody who
  207. X***************
  208. X*** 154,160 ****
  209. X              throw();
  210. X              break;
  211. X          case 'v':
  212. X!             message("rogue-clone: Version II. (Tim Stoehr was here), tektronix!zeus!tims", 0);
  213. X              break;
  214. X          case 'Q':
  215. X              quit(0);
  216. X--- 158,164 ----
  217. X              throw();
  218. X              break;
  219. X          case 'v':
  220. X!             message("rogue-clone: Version II+VMS (M Zraly was here), mzraly@ldbvax.dnet.lotus.com", 0);
  221. X              break;
  222. X          case 'Q':
  223. X              quit(0);
  224. X*** rogue.h.orig    Wed Aug 14 06:55:39 1991
  225. X--- rogue.h    Wed Aug 21 11:57:26 1991
  226. X***************
  227. X*** 1,4 ****
  228. X--- 1,8 ----
  229. X  /*
  230. X+  *    This code was adapted for VMS by Mike Zraly
  231. X+  */
  232. X+ 
  233. X+ /*
  234. X   * object.h
  235. X   *
  236. X   * This source herein may be modified and/or distributed by anybody who
  237. X***************
  238. X*** 9,14 ****
  239. X--- 13,22 ----
  240. X   *         gain or profit.
  241. X   *
  242. X   */
  243. X+ 
  244. X+ #ifdef VMS
  245. X+ #define getchar()    tt_getc()
  246. X+ #endif /* VMS */
  247. X  
  248. X  #define boolean char
  249. X  
  250. END_OF_FILE
  251. if test 1307 -ne `wc -c <'Patches03'`; then
  252.     echo shar: \"'Patches03'\" unpacked with wrong size!
  253. fi
  254. # end of 'Patches03'
  255. fi
  256. if test -f 'README.VMS' -a "${1}" != "-c" ; then 
  257.   echo shar: Will not clobber existing file \"'README.VMS'\"
  258. else
  259. echo shar: Extracting \"'README.VMS'\" \(1433 characters\)
  260. sed "s/^X//" >'README.VMS' <<'END_OF_FILE'
  261. XHere is how to get rogue running on VMS:
  262. X
  263. X1) unpack these sources -- if you have them in vms_share format,
  264. X   concatenate the different files in correct order into somefile.com,
  265. X   then type @somefile; if you have them in cshar format, you will
  266. X   either have to extract them on a UNIX system and then send them
  267. X   to your VMS system somehow, or manually unpack the files with
  268. X   your favorite editor.  (Ugh!)
  269. X
  270. X2) once you have all the files in one source directory, type
  271. X
  272. X    @make
  273. X
  274. X   to compile and link everything together.  Alternatively you
  275. X   could use the VMS make program available from either of the
  276. X   following anonymous FTP sites:
  277. X
  278. X    SITE:    pomona.claremont.edu
  279. X    IP-#:    134.173.4.160
  280. X    DIR:    [.utilities.make]
  281. X    FILES:    *.*
  282. X
  283. X    SITE:    vmsd.oac.uci.edu
  284. X    IP-#:    128.200.15.2
  285. X    DIR:    /
  286. X    FILES:    make_src.*
  287. X
  288. X   [Makefile.vms was generated by this make program]
  289. X
  290. X   Install it at your site and type
  291. X
  292. X    rename Makefile.vms  Makefile
  293. X    make
  294. X
  295. X   Either way, you may now play rogue by typing
  296. X
  297. X    rogue
  298. X
  299. X   but if you want to do it every session, you should put the
  300. X   following into your LOGIN.COM:
  301. X
  302. X    $ rogue :== $DISK:[DIRECTORY]rogue.exe
  303. X
  304. X   for example I might have
  305. X
  306. X    $ rogue :== $DISK$USER26:[MZRALY.ROGUE]
  307. X
  308. X   If you have any questions, try typing
  309. X
  310. X    help :=
  311. X
  312. X--
  313. X
  314. X
  315. XMike Zraly                ``Times are bad.  Children no longer
  316. Xmzraly@ldbvax.dnet.lotus.com          obey their parents, and everyone is
  317. Xor c/o seaotter@athena.mit.edu          writing a book.'' -- Cicero
  318. END_OF_FILE
  319. if test 1433 -ne `wc -c <'README.VMS'`; then
  320.     echo shar: \"'README.VMS'\" unpacked with wrong size!
  321. fi
  322. # end of 'README.VMS'
  323. fi
  324. if test -f 'machdep.c' -a "${1}" != "-c" ; then 
  325.   echo shar: Will not clobber existing file \"'machdep.c'\"
  326. else
  327. echo shar: Extracting \"'machdep.c'\" \(17495 characters\)
  328. sed "s/^X//" >'machdep.c' <<'END_OF_FILE'
  329. X/*
  330. X *    This code was adapted for VMS by Mike Zraly
  331. X */
  332. X
  333. X/*
  334. X * machdep.c
  335. X *
  336. X * This source herein may be modified and/or distributed by anybody who
  337. X * so desires, with the following restrictions:
  338. X *    1.)  No portion of this notice shall be removed.
  339. X *    2.)  Credit shall not be taken for the creation of this source.
  340. X *    3.)  This code is not to be traded, sold, or used for personal
  341. X *         gain or profit.
  342. X *
  343. X */
  344. X
  345. X/* Included in this file are all system dependent routines.  Extensive use
  346. X * of #ifdef's will be used to compile the appropriate code on each system:
  347. X *
  348. X *    UNIX:        all UNIX systems.
  349. X *    UNIX_BSD4_2: UNIX BSD 4.2 and later, UTEK, (4.1 BSD too?)
  350. X *    UNIX_SYSV:   UNIX system V
  351. X *    UNIX_V7:     UNIX version 7
  352. X *    VMS:    all VMS systems.
  353. X *
  354. X * All UNIX code should be included between the single "#ifdef UNIX" at the
  355. X * top of this file, and the "#endif UNIX" at the bottom.
  356. X * 
  357. X * To change a routine to include a new UNIX system, simply #ifdef the
  358. X * existing routine, as in the following example:
  359. X *
  360. X *   To make a routine compatible with UNIX system V, change the first
  361. X *   function to the second:
  362. X *
  363. X *      md_function()
  364. X *      {
  365. X *         code;
  366. X *      }
  367. X *
  368. X *      md_function()
  369. X *      {
  370. X *      #ifdef UNIX_SYSV
  371. X *         sysVcode;
  372. X *      #else
  373. X *         code;
  374. X *      #endif [* UNIX_SYSV *]
  375. X *      }
  376. X *
  377. X * Appropriate variations of this are of course acceptible.
  378. X * The use of "#elseif" is discouraged because of non-portability.
  379. X * If the correct #define doesn't exist, "UNIX_SYSV" in this case, make it up
  380. X * and insert it in the list at the top of the file.  Alter the CFLAGS
  381. X * in you Makefile appropriately.
  382. X *
  383. X */
  384. X
  385. X#include <stdio.h>
  386. X
  387. X#ifdef UNIX
  388. X#include <sys/types.h>
  389. X#include <sys/file.h>
  390. X#include <sys/stat.h>
  391. X#endif /* UNIX */
  392. X
  393. X#ifdef VMS
  394. X#include <types.h>
  395. X#include <file.h>
  396. X#include <stat.h>
  397. X#endif /* VMS */
  398. X
  399. X#ifdef UNIX_SYSV
  400. X#include <time.h>
  401. X#include <termio.h>
  402. X#endif /* UNIX_SYSV */
  403. X
  404. X#ifdef UNIX_BSD4_2
  405. X#include <sys/time.h>
  406. X#include <sgtty.h>
  407. X#endif /* UNIX_BSD4_2 */
  408. X
  409. X#ifdef VMS
  410. X#include <time.h>
  411. X#endif /* VMS */
  412. X
  413. X#include <signal.h>
  414. X#include "rogue.h"
  415. X
  416. X/* md_slurp:
  417. X *
  418. X * This routine throws away all keyboard input that has not
  419. X * yet been read.  It is used to get rid of input that the user may have
  420. X * typed-ahead.
  421. X *
  422. X * This function is not necessary, so it may be stubbed.  The might cause
  423. X * message-line output to flash by because the game has continued to read
  424. X * input without waiting for the user to read the message.  Not such a
  425. X * big deal.
  426. X */
  427. X
  428. Xmd_slurp()
  429. X{
  430. X#ifdef UNIX
  431. X    long ln = 0;
  432. X
  433. X#ifdef UNIX_BSD4_2
  434. X    ioctl(0, FIONREAD, &ln);
  435. X#endif /* UNIX_BSD4_2 */
  436. X#ifdef UNIX_SYSV
  437. X    ioctl(0, TCFLSH, &ln);
  438. X    ln = 0;
  439. X#endif /* UNIX_SYSV */
  440. X
  441. X    ln += stdin->_cnt;
  442. X
  443. X    for (; ln > 0; ln--) {
  444. X        (void) getchar();
  445. X    }
  446. X#endif /* UNIX */
  447. X#ifdef VMS
  448. X    tt_flush();
  449. X#endif /* VMS */
  450. X}
  451. X
  452. X/* md_control_keyboard():
  453. X *
  454. X * This routine is much like md_cbreak_no_echo_nonl() below.  It sets up the
  455. X * keyboard for appropriate input.  Specifically, it prevents the tty driver
  456. X * from stealing characters.  For example, ^Y is needed as a command
  457. X * character, but the tty driver intercepts it for another purpose.  Any
  458. X * such behavior should be stopped.  This routine could be avoided if
  459. X * we used RAW mode instead of CBREAK.  But RAW mode does not allow the
  460. X * generation of keyboard signals, which the program uses.
  461. X *
  462. X * The parameter 'mode' when true, indicates that the keyboard should
  463. X * be set up to play rogue.  When false, it should be restored if
  464. X * necessary.
  465. X *
  466. X * This routine is not strictly necessary and may be stubbed.  This may
  467. X * cause certain command characters to be unavailable.
  468. X */
  469. X
  470. Xmd_control_keybord(mode)
  471. Xboolean mode;
  472. X{
  473. X#ifdef UNIX
  474. X    static boolean called_before = 0;
  475. X#ifdef UNIX_BSD4_2
  476. X    static struct ltchars ltc_orig;
  477. X    static struct tchars tc_orig;
  478. X    struct ltchars ltc_temp;
  479. X    struct tchars tc_temp;
  480. X#endif /* UNIX_BSD4_2 */
  481. X#ifdef UNIX_SYSV
  482. X    static struct termio _oldtty;
  483. X    struct termio _tty;
  484. X#endif /* UNIX_SYSV */
  485. X
  486. X    if (!called_before) {
  487. X        called_before = 1;
  488. X#ifdef UNIX_BSD4_2
  489. X        ioctl(0, TIOCGETC, &tc_orig);
  490. X        ioctl(0, TIOCGLTC, <c_orig);
  491. X#endif /* UNIX_BSD4_2 */
  492. X#ifdef UNIX_SYSV
  493. X        ioctl(0, TCGETA, &_oldtty);
  494. X#endif /* UNIX_SYSV */
  495. X    }
  496. X#ifdef UNIX_BSD4_2
  497. X    ltc_temp = ltc_orig;
  498. X    tc_temp = tc_orig;
  499. X#endif /* UNIX_BSD4_2 */
  500. X#ifdef UNIX_SYSV
  501. X    _tty = _oldtty;
  502. X#endif /* UNIX_SYSV */
  503. X
  504. X    if (!mode) {
  505. X#ifdef UNIX_BSD4_2
  506. X        ltc_temp.t_suspc = ltc_temp.t_dsuspc = -1;
  507. X        ltc_temp.t_rprntc = ltc_temp.t_flushc = -1;
  508. X        ltc_temp.t_werasc = ltc_temp.t_lnextc = -1;
  509. X        tc_temp.t_startc = tc_temp.t_stopc = -1;
  510. X#endif /* UNIX_BSD4_2 */
  511. X#ifdef UNIX_SYSV
  512. X        _tty.c_cc[VSWTCH] = CNSWTCH;
  513. X#endif /* UNIX_SYSV */
  514. X    }
  515. X#ifdef UNIX_BSD4_2
  516. X    ioctl(0, TIOCSETC, &tc_temp);
  517. X    ioctl(0, TIOCSLTC, <c_temp);
  518. X#endif /* UNIX_BSD4_2 */
  519. X#ifdef UNIX_SYSV
  520. X    ioctl(0, TCSETA, &_tty);
  521. X#endif /* UNIX_SYSV */
  522. X#endif /* UNIX */
  523. X#ifdef VMS
  524. X    if (mode)
  525. X        tt_init();
  526. X    else
  527. X        tt_fini();
  528. X#endif /* VMS */
  529. X}
  530. X
  531. X/* md_heed_signals():
  532. X *
  533. X * This routine tells the program to call particular routines when
  534. X * certain interrupts/events occur:
  535. X *
  536. X *      SIGINT: call onintr() to interrupt fight with monster or long rest.
  537. X *      SIGQUIT: call byebye() to check for game termination.
  538. X *      SIGHUP: call error_save() to save game when terminal hangs up.
  539. X *
  540. X *        On VMS, SIGINT and SIGQUIT correspond to ^C and ^Y.
  541. X *
  542. X * This routine is not strictly necessary and can be stubbed.  This will
  543. X * mean that the game cannot be interrupted properly with keyboard
  544. X * input, this is not usually critical.
  545. X */
  546. X
  547. Xmd_heed_signals()
  548. X{
  549. X    signal(SIGINT, onintr);
  550. X    signal(SIGQUIT, byebye);
  551. X    signal(SIGHUP, error_save);
  552. X}
  553. X
  554. X/* md_ignore_signals():
  555. X *
  556. X * This routine tells the program to completely ignore the events mentioned
  557. X * in md_heed_signals() above.  The event handlers will later be turned on
  558. X * by a future call to md_heed_signals(), so md_heed_signals() and
  559. X * md_ignore_signals() need to work together.
  560. X *
  561. X * This function should be implemented or the user risks interrupting
  562. X * critical sections of code, which could cause score file, or saved-game
  563. X * file, corruption.
  564. X */
  565. X
  566. Xmd_ignore_signals()
  567. X{
  568. X    signal(SIGQUIT, SIG_IGN);
  569. X    signal(SIGINT, SIG_IGN);
  570. X    signal(SIGHUP, SIG_IGN);
  571. X}
  572. X
  573. X/* md_get_file_id():
  574. X *
  575. X * This function returns an integer that uniquely identifies the specified
  576. X * file.  It need not check for the file's existence.  In UNIX, the inode
  577. X * number is used.
  578. X *
  579. X * This function need not be implemented.  To stub the routine, just make
  580. X * it return 0.  This will make the game less able to prevent users from
  581. X * modifying saved-game files.  This is probably no big deal.
  582. X */
  583. X
  584. Xint
  585. Xmd_get_file_id(fname)
  586. Xchar *fname;
  587. X{
  588. X#ifdef UNIX
  589. X    struct stat sbuf;
  590. X
  591. X    if (stat(fname, &sbuf)) {
  592. X        return(-1);
  593. X    }
  594. X    return((int) sbuf.st_ino);
  595. X#endif /* UNIX */
  596. X#ifdef VMS
  597. X    return((int) 0);
  598. X#endif /* VMS */
  599. X}
  600. X
  601. X/* md_link_count():
  602. X *
  603. X * This routine returns the number of hard links to the specified file.
  604. X *
  605. X * This function is not strictly necessary.  On systems without hard links
  606. X * this routine can be stubbed by just returning 1.
  607. X */
  608. X
  609. Xint
  610. Xmd_link_count(fname)
  611. Xchar *fname;
  612. X{
  613. X#ifdef UNIX
  614. X    struct stat sbuf;
  615. X
  616. X    stat(fname, &sbuf);
  617. X    return((int) sbuf.st_nlink);
  618. X#endif /* UNIX */
  619. X#ifdef VMS
  620. X    return((int) 1);
  621. X#endif /* VMS */
  622. X}
  623. X
  624. X/* md_gct(): (Get Current Time)
  625. X *
  626. X * This function returns the current year, month(1-12), day(1-31), hour(0-23),
  627. X * minute(0-59), and second(0-59).  This is used for identifying the time
  628. X * at which a game is saved.
  629. X *
  630. X * This function is not strictly necessary.  It can be stubbed by returing
  631. X * zeros instead of the correct year, month, etc.  If your operating
  632. X * system doesn't provide all of the time units requested here, then you
  633. X * can provide only those that it does, and return zeros for the others.
  634. X * If you cannot provide good time values, then users may be able to copy
  635. X * saved-game files and play them.  
  636. X */
  637. X
  638. Xmd_gct(rt_buf)
  639. Xstruct rogue_time *rt_buf;
  640. X{
  641. X    struct tm *t, *localtime();
  642. X    time_t seconds = 0;
  643. X
  644. X    time(&seconds);
  645. X    t = localtime(&seconds);
  646. X
  647. X    rt_buf->year = t->tm_year;
  648. X    rt_buf->month = t->tm_mon + 1;
  649. X    rt_buf->day = t->tm_mday;
  650. X    rt_buf->hour = t->tm_hour;
  651. X    rt_buf->minute = t->tm_min;
  652. X    rt_buf->second = t->tm_sec;
  653. X}
  654. X
  655. X/* md_gfmt: (Get File Modification Time)
  656. X *
  657. X * This routine returns a file's date of last modification in the same format
  658. X * as md_gct() above.
  659. X *
  660. X * This function is not strictly necessary.  It is used to see if saved-game
  661. X * files have been modified since they were saved.  If you have stubbed the
  662. X * routine md_gct() above by returning constant values, then you may do
  663. X * exactly the same here.
  664. X * Or if md_gct() is implemented correctly, but your system does not provide
  665. X * file modification dates, you may return some date far in the past so
  666. X * that the program will never know that a saved-game file being modified.  
  667. X * You may also do this if you wish to be able to restore games from
  668. X * saved-games that have been modified.
  669. X */
  670. X
  671. Xmd_gfmt(fname, rt_buf)
  672. Xchar *fname;
  673. Xstruct rogue_time *rt_buf;
  674. X{
  675. X    struct stat sbuf;
  676. X    time_t seconds;
  677. X    struct tm *t;
  678. X
  679. X    stat(fname, &sbuf);
  680. X    seconds = (time_t) sbuf.st_mtime;
  681. X    t = localtime(&seconds);
  682. X
  683. X    rt_buf->year = t->tm_year;
  684. X    rt_buf->month = t->tm_mon + 1;
  685. X    rt_buf->day = t->tm_mday;
  686. X    rt_buf->hour = t->tm_hour;
  687. X    rt_buf->minute = t->tm_min;
  688. X    rt_buf->second = t->tm_sec;
  689. X}
  690. X
  691. X/* md_df: (Delete File)
  692. X *
  693. X * This function deletes the specified file, and returns true (1) if the
  694. X * operation was successful.  This is used to delete saved-game files
  695. X * after restoring games from them.
  696. X *
  697. X * Again, this function is not strictly necessary, and can be stubbed
  698. X * by simply returning 1.  In this case, saved-game files will not be
  699. X * deleted and can be replayed.
  700. X */
  701. X
  702. Xboolean
  703. Xmd_df(fname)
  704. Xchar *fname;
  705. X{
  706. X#ifdef VMS
  707. X#define unlink delete
  708. X#endif /* VMS */
  709. X
  710. X    if (unlink(fname)) {
  711. X        return(0);
  712. X    }
  713. X    return(1);
  714. X}
  715. X
  716. X/* md_gln: (Get login name)
  717. X *
  718. X * This routine returns the login name of the user.  This string is
  719. X * used mainly for identifying users in score files.
  720. X *
  721. X * A dummy string may be returned if you are unable to implement this
  722. X * function, but then the score file would only have one name in it.
  723. X */
  724. X
  725. Xchar *
  726. Xmd_gln()
  727. X{
  728. X#ifdef UNIX
  729. X    char *getlogin();
  730. X    char *t;
  731. X
  732. X    t = getlogin();
  733. X    return(t);
  734. X#endif /* UNIX */
  735. X#ifdef VMS
  736. X    return((char *)getenv("USER"));
  737. X#endif /* VMS */
  738. X}
  739. X
  740. X/* md_sleep:
  741. X *
  742. X * This routine causes the game to pause for the specified number of
  743. X * seconds.
  744. X *
  745. X * This routine is not necessary at all, and can be stubbed with no ill
  746. X * effects.
  747. X */
  748. X
  749. Xmd_sleep(nsecs)
  750. Xint nsecs;
  751. X{
  752. X    (void) sleep(nsecs);
  753. X}
  754. X
  755. X/* md_getenv()
  756. X *
  757. X * This routine gets certain values from the user's environment.  These
  758. X * values are strings, and each string is identified by a name.  The names
  759. X * of the values needed, and their use, is as follows:
  760. X *
  761. X *   TERMCAP
  762. X *     The name of the users's termcap file, NOT the termcap entries
  763. X *     themselves.  This is used ONLY if the program is compiled with
  764. X *     CURSES defined (-DCURSES).  Even in this case, the program need
  765. X *     not find a string for TERMCAP.  If it does not, it will use the
  766. X *     default termcap file as returned by md_gdtcf();
  767. X *   TERM
  768. X *     The name of the users's terminal.  This is used ONLY if the program
  769. X *     is compiled with CURSES defined (-DCURSES).  In this case, the string
  770. X *     value for TERM must be found, or the routines in curses.c cannot
  771. X *     function, and the program will quit.
  772. X *   ROGUEOPTS
  773. X *     A string containing the various game options.  This need not be
  774. X *     defined.
  775. X *   HOME
  776. X *     The user's home directory.  This is only used when the user specifies
  777. X *     '~' as the first character of a saved-game file.  This string need
  778. X *     not be defined.
  779. X *
  780. X * If your system does not provide a means of searching for these values,
  781. X * you will have to do it yourself.  None of the values above really need
  782. X * to be defined except TERM when the program is compiled with CURSES
  783. X * defined.  In this case, as a bare minimum, you can check the 'name'
  784. X * parameter, and if it is "TERM" find the terminal name and return that,
  785. X * else return zero.  If the program is not compiled with CURSES, you can
  786. X * get by with simply always returning zero.  Returning zero indicates
  787. X * that their is no defined value for the given string.
  788. X */
  789. X
  790. Xchar *
  791. Xmd_getenv(name)
  792. Xchar *name;
  793. X{
  794. X#ifdef UNIX
  795. X    char *value;
  796. X    char *getenv();
  797. X
  798. X    value = getenv(name);
  799. X
  800. X    return(value);
  801. X#endif /* UNIX */
  802. X#ifdef VMS
  803. X    return((char *)getenv(name));
  804. X#endif /* VMS */
  805. X}
  806. X
  807. X/* md_malloc()
  808. X *
  809. X * This routine allocates, and returns a pointer to, the specified number
  810. X * of bytes.  This routines absolutely MUST be implemented for your
  811. X * particular system or the program will not run at all.  Return zero
  812. X * when no more memory can be allocated.
  813. X */
  814. X
  815. Xchar *
  816. Xmd_malloc(n)
  817. Xint n;
  818. X{
  819. X    char *malloc();
  820. X    char *t;
  821. X
  822. X    t = malloc(n);
  823. X    return(t);
  824. X}
  825. X
  826. X/* md_gseed() (Get Seed)
  827. X *
  828. X * This function returns a seed for the random number generator (RNG).  This
  829. X * seed causes the RNG to begin generating numbers at some point in it's
  830. X * sequence.  Without a random seed, the RNG will generate the same set
  831. X * of numbers, and every game will start out exactly the same way.  A good
  832. X * number to use is the process id, given by getpid() on most UNIX systems.
  833. X *
  834. X * You need to find some single random integer, such as:
  835. X *   process id.
  836. X *   current time (minutes + seconds) returned from md_gct(), if implemented.
  837. X *   
  838. X * It will not help to return "get_rand()" or "rand()" or the return value of
  839. X * any pseudo-RNG.  If you don't have a random number, you can just return 1,
  840. X * but this means your games will ALWAYS start the same way, and will play
  841. X * exactly the same way given the same input.
  842. X */
  843. X
  844. Xmd_gseed()
  845. X{
  846. X    return((time((time_t *)0) & ~((int)0)) + getpid());
  847. X}
  848. X
  849. X/* md_exit():
  850. X *
  851. X * This function causes the program to discontinue execution and exit.
  852. X * This function must be implemented or the program will continue to
  853. X * hang when it should quit.
  854. X */
  855. X
  856. Xmd_exit(status)
  857. Xint status;
  858. X{
  859. X    exit(status);
  860. X}
  861. X
  862. X/* If you have a viable curses/termlib library, then use it and don't bother
  863. X * implementing the routines below.  And don't compile with -DCURSES.
  864. X */
  865. X
  866. X#ifdef CURSES
  867. X
  868. X/* md_cbreak_no_echo_nonl:
  869. X *
  870. X * This routine sets up some terminal characteristics.  The tty-driver
  871. X * must be told to:
  872. X *   1.)  Not echo input.
  873. X *   2.)  Transmit input characters immediately upon typing. (cbreak mode)
  874. X *   3.)  Move the cursor down one line, without changing column, and
  875. X *        without generating a carriage-return, when it
  876. X *        sees a line-feed.  This is only necessary if line-feed is ever
  877. X *        used in the termcap 'do' (cursor down) entry, in which case,
  878. X *        your system should must have a way of accomplishing this.
  879. X *
  880. X * When the parameter 'on' is true, the terminal is set up as specified
  881. X * above.  When this parameter is false, the terminal is restored to the
  882. X * original state.
  883. X *
  884. X * Raw mode should not to be used.  Keyboard signals/events/interrupts should
  885. X * be sent, although they are not strictly necessary.  See notes in
  886. X * md_heed_signals().
  887. X *
  888. X * This function must be implemented for rogue to run properly if the
  889. X * program is compiled with CURSES defined to use the enclosed curses
  890. X * emulation package.  If you are not using this, then this routine is
  891. X * totally unnecessary.
  892. X * 
  893. X * Notice that information is saved between calls.  This is used to
  894. X * restore the terminal to an initial saved state.
  895. X *
  896. X */
  897. X
  898. Xmd_cbreak_no_echo_nonl(on)
  899. Xboolean on;
  900. X{
  901. X#ifdef UNIX
  902. X#ifdef UNIX_BSD4_2
  903. X    static struct sgttyb tty_buf;
  904. X    static int tsave_flags;
  905. X
  906. X    if (on) {
  907. X        ioctl(0, TIOCGETP, &tty_buf);
  908. X        tsave_flags = tty_buf.sg_flags;
  909. X        tty_buf.sg_flags |= CBREAK;
  910. X        tty_buf.sg_flags &= ~(ECHO | CRMOD);    /* CRMOD: see note 3 above */
  911. X        ioctl(0, TIOCSETP, &tty_buf);
  912. X    } else {
  913. X        tty_buf.sg_flags = tsave_flags;
  914. X        ioctl(0, TIOCSETP, &tty_buf);
  915. X    }
  916. X#endif /* UNIX_BSD4_2 */
  917. X#ifdef UNIX_SYSV
  918. X    struct termio tty_buf;
  919. X    static struct termio tty_save;
  920. X
  921. X    if (on) {
  922. X        ioctl(0, TCGETA, &tty_buf);
  923. X        tty_save = tty_buf;
  924. X        tty_buf.c_lflag &= ~(ICANON | ECHO);
  925. X        tty_buf.c_oflag &= ~ONLCR;
  926. X        tty_buf.c_cc[4] = 1;  /* MIN */
  927. X        tty_buf.c_cc[5] = 2;  /* TIME */
  928. X        ioctl(0, TCSETAF, &tty_buf);
  929. X    } else {
  930. X        ioctl(0, TCSETAF, &tty_save);
  931. X    }
  932. X#endif /* UNIX_SYSV */
  933. X#endif /* UNIX */
  934. X#ifdef VMS
  935. X    if (on)
  936. X        tt_init();
  937. X    else
  938. X        tt_fini();
  939. X#endif /* VMS */
  940. X}
  941. X
  942. X/* md_gdtcf(): (Get Default Termcap File)
  943. X *
  944. X * This function is called ONLY when the program is compiled with CURSES
  945. X * defined.  If you use your system's curses/termlib library, this function
  946. X * won't be called.  On most UNIX systems, "/etc/termcap" suffices.
  947. X *
  948. X * If their is no such termcap file, then return 0, but in that case, you
  949. X * must have a TERMCAP file returned from md_getenv("TERMCAP").  The latter
  950. X * will override the value returned from md_gdtcf().  If the program is
  951. X * compiled with CURSES defined, and md_gdtcf() returns 0, and
  952. X * md_getenv("TERMCAP") returns 0, the program will have no terminal
  953. X * capability information and will quit.
  954. X */
  955. X
  956. Xchar *
  957. Xmd_gdtcf()
  958. X{
  959. X#ifdef UNIX
  960. X    return("/etc/termcap");
  961. X#endif /* UNIX */
  962. X#ifdef VMS
  963. X    return(getenv("TERMCAP"));
  964. X#endif /* VMS */
  965. X}
  966. X
  967. X/* md_tstp():
  968. X *
  969. X * This function puts the game to sleep and returns to the shell.  This
  970. X * only applies to UNIX 4.2 and 4.3.  For other systems, the routine should
  971. X * be provided as a do-nothing routine.  md_tstp() will only be referenced
  972. X * in the code when compiled with CURSES defined.
  973. X *
  974. X */
  975. X
  976. Xmd_tstp()
  977. X{
  978. X#ifdef UNIX_BSD4_2
  979. X    kill(0, SIGTSTP);
  980. X#endif /* UNIX_BSD4_2 */
  981. X}
  982. X
  983. X#endif /* CURSES */
  984. END_OF_FILE
  985. if test 17495 -ne `wc -c <'machdep.c'`; then
  986.     echo shar: \"'machdep.c'\" unpacked with wrong size!
  987. fi
  988. # end of 'machdep.c'
  989. fi
  990. if test -f 'vmsterm.c' -a "${1}" != "-c" ; then 
  991.   echo shar: Will not clobber existing file \"'vmsterm.c'\"
  992. else
  993. echo shar: Extracting \"'vmsterm.c'\" \(5996 characters\)
  994. sed "s/^X//" >'vmsterm.c' <<'END_OF_FILE'
  995. X#ifdef VMS
  996. X
  997. X
  998. X/*
  999. X *    VMSTERM.C
  1000. X *
  1001. X *    Copyright (c) 1991 by Michael S Zraly.
  1002. X *
  1003. X *    Some of the details in this code were derived from code
  1004. X *    for the games larn, copyright 1986 by Noah Morgan (as
  1005. X *    adapted by Kevin Routley), and nethack, copyright 1985
  1006. X *    by the Stichting Mathematisch centrum, Amsterdam.
  1007. X *
  1008. X *    Permission is granted to distribute and modify this source
  1009. X *    Permission is granted to distribute and modify this source
  1010. X *    freely, provided that no charge is made for doing so and
  1011. X *    that this comment remains untouched.
  1012. X *
  1013. X *    Last Modified:    21 August 1991
  1014. X */
  1015. X
  1016. X
  1017. X#include    <descrip.h>
  1018. X#include    "vmsterm.h"
  1019. X
  1020. X
  1021. X#define    TT_BUFSIZ    80
  1022. X
  1023. X
  1024. X/*
  1025. X *    I/o func codes passed to SYS$QIO() or SYS$QIOW():
  1026. X */
  1027. X#define    TT_NOPURGE    (IO$_READLBLK|IO$M_NOFILTR|IO$M_TIMED|IO$M_NOECHO)
  1028. X#define    TT_PURGE    ((TT_NOPURGE)|(IO$M_PURGE))
  1029. X
  1030. X
  1031. X/*
  1032. X *    Default terminal characteristics
  1033. X */
  1034. X#define    TT_TTDEFS    (TT$M_MECHTAB|TT$M_MECHFORM|TT$M_NOECHO)
  1035. X#define    TT_TT2DEFS    (TT2$M_PASTHRU)
  1036. X
  1037. X
  1038. X/*
  1039. X *    Macro functions to get and
  1040. X *    set terminal characteristics
  1041. X */
  1042. X#define    tt_getmode(iosb_s,ttbuf)                \
  1043. X    ( ((SYS$QIOW(0, tt_chan(), IO$_SENSEMODE, &(iosb_s),    \
  1044. X    (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0)    \
  1045. X    & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
  1046. X
  1047. X#define    tt_setmode(iosb_s,ttbuf)                \
  1048. X    ( ((SYS$QIOW(0, tt_chan(), IO$_SETMODE, &(iosb_s),    \
  1049. X    (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0)    \
  1050. X    & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
  1051. X
  1052. X
  1053. X/*
  1054. X *    Private (static) variables
  1055. X */
  1056. Xstatic    int        _io_on = 0;    /* between tt_init & tt_fini */
  1057. Xstatic    int        _io_pu = 0;    /* purge typeahead on next read */
  1058. Xstatic    int        _iochan = 0;    /* channel for i/o */
  1059. Xstatic    IOSB_S        _iosb;
  1060. Xstatic    TTBUF        _ttbuf_old;
  1061. Xstatic    TTBUF        _ttbuf_new;
  1062. X
  1063. X
  1064. X/*
  1065. X -    (static) tt_getchannel :
  1066. X */
  1067. Xstatic int tt_getchannel ()
  1068. X{
  1069. X    struct dsc$descriptor_s    iodsc;
  1070. X
  1071. X    if (_iochan > 0)
  1072. X        return TT_SUCCESS;    /* already assigned channel */
  1073. X
  1074. X    iodsc.dsc$w_length    = sizeof("TT:")-1;
  1075. X    iodsc.dsc$b_dtype    = DSC$K_DTYPE_T;
  1076. X    iodsc.dsc$b_class    = DSC$K_CLASS_S;
  1077. X    iodsc.dsc$a_pointer    = "TT:";
  1078. X
  1079. X    if ((SYS$ASSIGN (&iodsc, &_iochan, 0, 0) & SS$_NORMAL) == 0)
  1080. X        return TT_FAILURE;
  1081. X
  1082. X    return TT_SUCCESS;
  1083. X}
  1084. X
  1085. X
  1086. X/*
  1087. X -    (static) tt_freechannel :
  1088. X */
  1089. Xstatic int tt_freechannel ()
  1090. X{
  1091. X    int    status;
  1092. X
  1093. X    if (_iochan == 0)
  1094. X        return TT_SUCCESS;    /* channel not assigned */
  1095. X
  1096. X    status = SYS$DASSGN (_iochan);
  1097. X
  1098. X    _iochan = 0;
  1099. X
  1100. X    if ((status & SS$_NORMAL) == 0)
  1101. X        return TT_FAILURE;
  1102. X
  1103. X    return TT_SUCCESS;
  1104. X}
  1105. X
  1106. X
  1107. X/*
  1108. X -    (static) vms_read :
  1109. X */
  1110. Xstatic int vms_read (char *buffer, int size, int timeout)
  1111. X{
  1112. X    int        code;
  1113. X    int        status;
  1114. X    IOSB_R        iostab;
  1115. X    static int    tt_terms[2] = { 0, 0 };
  1116. X
  1117. X    if (_io_pu == 1)
  1118. X        code = TT_PURGE;
  1119. X    else
  1120. X        code = TT_NOPURGE;
  1121. X
  1122. X    _io_pu = 0;
  1123. X
  1124. X    status = SYS$QIOW (0, _iochan, code,
  1125. X        &iostab, (void(*)())0, 0,
  1126. X        buffer, size, timeout, tt_terms, 0, 0);
  1127. X
  1128. X    if (status == SS$_TIMEOUT)
  1129. X        return TT_TIMEOUT;
  1130. X
  1131. X    if (status != SS$_NORMAL)
  1132. X        return TT_ERROR;
  1133. X
  1134. X    if ((status = iostab.term_offset + iostab.term_size) > 0)
  1135. X        return status;
  1136. X
  1137. X    return TT_TIMEOUT;
  1138. X}
  1139. X
  1140. X
  1141. X/*
  1142. X -    tt_chan :
  1143. X */
  1144. Xint tt_chan ()
  1145. X{
  1146. X    if (_iochan == 0)
  1147. X        (void) tt_getchannel();
  1148. X
  1149. X    return _iochan;
  1150. X}
  1151. X
  1152. X
  1153. X/*
  1154. X -    tt_init :
  1155. X */
  1156. Xint tt_init ()
  1157. X{
  1158. X    if (_io_on == 1)
  1159. X        return TT_SUCCESS;
  1160. X
  1161. X    if (tt_getchannel() == TT_FAILURE)
  1162. X        return TT_FAILURE;
  1163. X
  1164. X    if (tt_getmode(_iosb, _ttbuf_old) == TT_FAILURE)
  1165. X        return TT_FAILURE;
  1166. X
  1167. X    if (tt_getmode(_iosb, _ttbuf_new) == TT_FAILURE)
  1168. X        return TT_FAILURE;
  1169. X
  1170. X    _ttbuf_new.ttchar |= TT_TTDEFS;
  1171. X    _ttbuf_new.tt2char |= TT_TT2DEFS;
  1172. X
  1173. X    if (tt_setmode(_iosb, _ttbuf_new) == TT_FAILURE) {
  1174. X        (void) tt_fini ();
  1175. X        return TT_FAILURE;
  1176. X    }
  1177. X
  1178. X    if (atexit(tt_fini) != 0) {
  1179. X        (void) tt_fini ();
  1180. X        return TT_FAILURE;
  1181. X    }
  1182. X
  1183. X    _io_on = 1;
  1184. X    return TT_SUCCESS;
  1185. X}
  1186. X
  1187. X
  1188. X/*
  1189. X -    tt_getc :
  1190. X */
  1191. Xint tt_getc ()
  1192. X{
  1193. X    int        incount;
  1194. X    static char    buffer[TT_BUFSIZ];
  1195. X    static char    *bufptr = buffer;
  1196. X    static char    *bufend = buffer;
  1197. X
  1198. X    /*
  1199. X     *    If io not initialized, do so.
  1200. X     */
  1201. X
  1202. X    if (_io_on == 0)
  1203. X        if (tt_init() == TT_FAILURE)
  1204. X            return TT_ERROR;
  1205. X
  1206. X    /*
  1207. X     *    First call to vms_read reads any leftover
  1208. X     *    characters from operating system's read
  1209. X     *    buffer -- it should return TIMEOUT.  Then
  1210. X     *    call again and again until a character
  1211. X     *    is successfully read.
  1212. X     */
  1213. X
  1214. X    if (bufptr >= bufend) {
  1215. X        bufptr = bufend = buffer;
  1216. X        incount = vms_read (buffer, TT_BUFSIZ, 0);
  1217. X        while (incount < TT_SUCCESS)
  1218. X            incount = vms_read (buffer, 1, 2);
  1219. X        bufend = &buffer[incount];
  1220. X    }
  1221. X
  1222. X    /*
  1223. X     *    If escape was read, call vms_read with
  1224. X     *    timeout 0 to read all characters in the
  1225. X     *    escape sequence.
  1226. X     */
  1227. X
  1228. X    if (*bufptr == '\033') {
  1229. X        char    junk[80];
  1230. X
  1231. X        (void) vms_read(junk, 80, 0);
  1232. X        bufptr = bufend = buffer;
  1233. X
  1234. X        return    '\033';
  1235. X    }
  1236. X
  1237. X    *bufend = '\0';
  1238. X
  1239. X    return (*bufptr++ & 0177);
  1240. X}
  1241. X
  1242. X
  1243. X/*
  1244. X -    tt_flush :
  1245. X */
  1246. Xvoid tt_flush ()
  1247. X{
  1248. X    /*
  1249. X     * Alternatively we could call vms_read with 0 timeout
  1250. X     * until no more characters are available, i.e.
  1251. X     *
  1252. X     *    char    ch;
  1253. X     *
  1254. X     *    while (vms_read(&ch, 1, 0) > TT_FAILURE)
  1255. X     *        ;
  1256. X     *
  1257. X     * Hopefully the final vms_read() will return TT_TIMEOUT
  1258. X     */
  1259. X    _io_pu = 1;
  1260. X    return;
  1261. X}
  1262. X
  1263. X
  1264. X/*
  1265. X -    tt_fini :
  1266. X */
  1267. Xvoid tt_fini ()
  1268. X{
  1269. X    if (_io_on == 0)
  1270. X        return;
  1271. X
  1272. X    (void) tt_setmode (_iosb, _ttbuf_old);
  1273. X
  1274. X    /*
  1275. X     *    De-assign io channel.
  1276. X     */
  1277. X
  1278. X    (void) tt_freechannel ();
  1279. X
  1280. X    _io_on = 0;
  1281. X    return;
  1282. X}
  1283. X
  1284. X
  1285. X/*
  1286. X -    tt_speed :
  1287. X */
  1288. Xint tt_speed ()
  1289. X{
  1290. X    if (_io_on == 0)
  1291. X        if (tt_init() == TT_FAILURE)
  1292. X            return TT_ERROR;
  1293. X
  1294. X    if (_iosb.ospeed < BAUD_MIN || _iosb.ospeed > BAUD_MAX)
  1295. X        return TT_FAILURE;
  1296. X    else
  1297. X        return _iosb.ospeed;
  1298. X}
  1299. X
  1300. X
  1301. X/*
  1302. X -    tt_cols :
  1303. X */
  1304. Xint tt_cols ()
  1305. X{
  1306. X    if (_io_on == 0)
  1307. X        if (tt_init() == TT_FAILURE)
  1308. X            return TT_ERROR;
  1309. X
  1310. X    if (_ttbuf_new.cols > 0)
  1311. X        return _ttbuf_new.cols;
  1312. X
  1313. X    return TT_ERROR;
  1314. X}
  1315. X
  1316. X
  1317. X/*
  1318. X -    tt_rows :
  1319. X */
  1320. Xint tt_rows ()
  1321. X{
  1322. X    if (_io_on == 0)
  1323. X        if (tt_init() == TT_FAILURE)
  1324. X            return TT_ERROR;
  1325. X
  1326. X    if (_ttbuf_new.rows > 0)
  1327. X        return _ttbuf_new.rows;
  1328. X
  1329. X    return TT_ERROR;
  1330. X}
  1331. X
  1332. X
  1333. X/*
  1334. X -    tt_shell :
  1335. X */
  1336. Xvoid tt_shell ()
  1337. X{
  1338. X    long            status;
  1339. X    struct dsc$descriptor_s    dsc;
  1340. X
  1341. X    dsc.dsc$w_length    = sizeof("")-1;
  1342. X    dsc.dsc$b_dtype        = DSC$K_DTYPE_T;
  1343. X    dsc.dsc$b_class        = DSC$K_CLASS_S;
  1344. X    dsc.dsc$a_pointer    = "";
  1345. X
  1346. X    (void) LIB$SPAWN (&dsc, 0, 0, 0, 0, 0, &status, 0, 0, 0, 0, 0);
  1347. X
  1348. X    return;
  1349. X}
  1350. X#endif                    /* VMS */
  1351. END_OF_FILE
  1352. if test 5996 -ne `wc -c <'vmsterm.c'`; then
  1353.     echo shar: \"'vmsterm.c'\" unpacked with wrong size!
  1354. fi
  1355. # end of 'vmsterm.c'
  1356. fi
  1357. if test -f 'vmsterm.h' -a "${1}" != "-c" ; then 
  1358.   echo shar: Will not clobber existing file \"'vmsterm.h'\"
  1359. else
  1360. echo shar: Extracting \"'vmsterm.h'\" \(3313 characters\)
  1361. sed "s/^X//" >'vmsterm.h' <<'END_OF_FILE'
  1362. X#ifndef __VMSTERM_LOADED
  1363. X#define __VMSTERM_LOADED    1
  1364. X#ifdef VMS
  1365. X
  1366. X
  1367. X/*
  1368. X *    VMSTERM.H
  1369. X *
  1370. X *    Copyright (c) 1991 by Michael S Zraly.
  1371. X *
  1372. X *    Some of the details in this code were derived from code
  1373. X *    for the games larn, copyright 1986 by Noah Morgan (as
  1374. X *    adapted by Kevin Routley), and nethack, copyright 1985
  1375. X *    by the Stichting Mathematisch centrum, Amsterdam.
  1376. X *
  1377. X *    Permission is granted to distribute and modify this source
  1378. X *    freely, provided that no charge is made for doing so and
  1379. X *    that this comment remains untouched.
  1380. X *
  1381. X *    Last Modified:    21 August 1991
  1382. X */
  1383. X
  1384. X
  1385. X#include    <iodef.h>
  1386. X#include    <ssdef.h>
  1387. X#include    <ttdef.h>
  1388. X#include    <tt2def.h>
  1389. X
  1390. X
  1391. X/*
  1392. X *    Return codes:
  1393. X */
  1394. X#define    TT_SUCCESS    1
  1395. X#define    TT_FAILURE    0
  1396. X#define    TT_ERROR    (-1)
  1397. X#define    TT_TIMEOUT    (-2)
  1398. X
  1399. X
  1400. X/*
  1401. X *    These speed codes are for compatability with BSD UNIX
  1402. X */
  1403. X#define    B0    (-1)            /* no VMS equivalent */
  1404. X#define    B50    TT$C_BAUD_50
  1405. X#define    B75    TT$C_BAUD_75
  1406. X#define    B110    TT$C_BAUD_110
  1407. X#define    B134    TT$C_BAUD_134
  1408. X#define    B150    TT$C_BAUD_150
  1409. X#define    B200    B150            /* no VMS equivalent */
  1410. X#define    B300    TT$C_BAUD_300
  1411. X#define    B600    TT$C_BAUD_600
  1412. X#define    B1200    TT$C_BAUD_1200
  1413. X#define    B1800    TT$C_BAUD_1800
  1414. X#define    B2000    TT$C_BAUD_2000        /* no BSD equivalent */
  1415. X#define    B2400    TT$C_BAUD_2400
  1416. X#define    B3600    TT$C_BAUD_3600        /* no BSD equivalent */
  1417. X#define    B4800    TT$C_BAUD_4800
  1418. X#define    B7200    TT$C_BAUD_7200        /* no BSD equivalent */
  1419. X#define    B9600    TT$C_BAUD_9600
  1420. X#define    B19200    TT$C_BAUD_19200        /* no BSD equivalent */
  1421. X#define    B38400    TT$C_BAUD_38400        /* no BSD equivalent */
  1422. X#define    EXTA    B50            /* no VMS equivalent */
  1423. X#define    EXTB    B50            /* no VMS equivalent */
  1424. X
  1425. X#define    BAUD_MIN    B50
  1426. X#define    BAUD_MAX    B38400
  1427. X
  1428. X
  1429. X/*
  1430. X *    This is the i/o status block structure returned from
  1431. X *    an IO$_READxBLK call to SYS$QIO() or SYS$QIOW().
  1432. X */
  1433. Xtypedef struct {
  1434. X   unsigned status    : 16;
  1435. X   unsigned term_offset    : 16;
  1436. X   unsigned terminator    : 16;
  1437. X   unsigned term_size    : 16;
  1438. X} IOSB_R;
  1439. X
  1440. X
  1441. X/*
  1442. X *    This is the i/o status block structure returned from
  1443. X *    an IO$_SENSEMODE or IO$_SETMODE call to SYS$QIO() or
  1444. X *    SYS$QIOW().
  1445. X */
  1446. Xtypedef struct {
  1447. X   unsigned status    : 16;
  1448. X   unsigned ospeed    :  8;
  1449. X   unsigned ispeed    :  8;
  1450. X   unsigned cr_fill    :  8;
  1451. X   unsigned lf_fill    :  8;
  1452. X   unsigned parity    :  8;
  1453. X   unsigned unused    :  8;
  1454. X} IOSB_S;
  1455. X
  1456. X
  1457. X/*
  1458. X *    This is the structure describing terminal characteristics
  1459. X *    passed as the P1 argument in an IO$_SENSEMODE or IO$_SET-
  1460. X *    MODE call to SYS$QIO() or SYS$QIOW().
  1461. X */
  1462. Xtypedef struct {
  1463. X   unsigned class    :  8;
  1464. X   unsigned type    :  8;
  1465. X   unsigned cols    : 16;
  1466. X   unsigned ttchar    : 24;    /* see <ttdef.h> */
  1467. X   unsigned rows    :  8;
  1468. X   unsigned tt2char    : 32;    /* see <tt2def.h> */
  1469. X} TTBUF;
  1470. X
  1471. X
  1472. X/*
  1473. X *    Macro functions to get and
  1474. X *    set terminal characteristics
  1475. X */
  1476. X#define    tt_getmode(iosb_s,ttbuf)                \
  1477. X    ( ((SYS$QIOW(0, tt_chan(), IO$_SENSEMODE, &(iosb_s),    \
  1478. X    (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0)    \
  1479. X    & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
  1480. X
  1481. X#define    tt_setmode(iosb_s,ttbuf)                \
  1482. X    ( ((SYS$QIOW(0, tt_chan(), IO$_SETMODE, &(iosb_s),    \
  1483. X    (void(*)())0, 0, &(ttbuf), sizeof(ttbuf), 0, 0, 0, 0)    \
  1484. X    & SS$_NORMAL) == 0) ? TT_FAILURE : TT_SUCCESS )
  1485. X
  1486. X
  1487. X/*
  1488. X *    Prototypes:
  1489. X */
  1490. Xint    tt_chan();
  1491. Xint    tt_init();
  1492. Xint    tt_getc();
  1493. Xvoid    tt_flush();
  1494. Xvoid    tt_fini();
  1495. Xint    tt_speed();
  1496. Xint    tt_cols();
  1497. Xint    tt_rows();
  1498. Xvoid    tt_shell();
  1499. X
  1500. X
  1501. X#endif                    /* VMS */
  1502. X#endif                    /* __VMSTERM_LOADED */
  1503. END_OF_FILE
  1504. if test 3313 -ne `wc -c <'vmsterm.h'`; then
  1505.     echo shar: \"'vmsterm.h'\" unpacked with wrong size!
  1506. fi
  1507. # end of 'vmsterm.h'
  1508. fi
  1509. echo shar: End of shell archive.
  1510. exit 0
  1511.